<?php
namespace app\api\controller;
use app\api\model\UserToken;
use app\lib\exception\TokenException;
use app\Validate\ApiValidate;
use think\Controller;
use think\Request;

class HomeCommon extends Controller
{
    /**
     * @param Request $request
     * @throws TokenException
     * @throws \app\lib\exception\ParameterException
     */
    public function initialize()
    {
        define("TestPrice",2);
        (new ApiValidate())->goCheck();
         $post = \think\facade\Request::post();
         $where = [
             ['token','eq',$post['token']],
             ['user_id','eq',$post['user_id']],
             ['overDay_time','gt',time()]
         ];
         $count = (new UserToken())->getCount($where);
         if($count==0){
             throw  new TokenException(['msg'=>'token失效']);
         }
    }
    // 处理图片路径
    function imgUrlToAbsolute($img = '') {

        if (stripos($img, 'http') === false) {
            return "http://". $_SERVER['SERVER_NAME'] . $img;
        } else {
            return $img;
        }

    }

}